package com.hz.monitoring.module.hardware.dal.mysql.mcu_tenant_resource;

import com.hz.monitoring.framework.common.pojo.PageResult;
import com.hz.monitoring.framework.mybatis.core.mapper.BaseMapperX;
import com.hz.monitoring.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.hz.monitoring.module.hardware.controller.admin.mcu_tenant_resource.vo.McuTenantResourceExportReqVO;
import com.hz.monitoring.module.hardware.controller.admin.mcu_tenant_resource.vo.McuTenantResourceListReqVO;
import com.hz.monitoring.module.hardware.controller.admin.mcu_tenant_resource.vo.McuTenantResourcePageReqVO;
import com.hz.monitoring.module.hardware.dal.dataobject.mcu_tenant_resource.McuTenantResourceDO;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;
import java.util.Objects;

/**
 * MCU租户配置 Mapper
 *
 * @author 芋道源码
 */
@Mapper
public interface McuTenantResourceMapper extends BaseMapperX<McuTenantResourceDO> {

    default PageResult<McuTenantResourceDO> selectPage(McuTenantResourcePageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<McuTenantResourceDO>()
                .eqIfPresent(McuTenantResourceDO::getModel, reqVO.getModel())
                .likeIfPresent(McuTenantResourceDO::getName, reqVO.getName())
                .likeIfPresent(McuTenantResourceDO::getRemark, reqVO.getRemark())
                .likeIfPresent(McuTenantResourceDO::getCorrelationIp, reqVO.getCorrelationIp())
                .eqIfPresent(McuTenantResourceDO::getTenantId,reqVO.getTenantId())
                .betweenIfPresent(McuTenantResourceDO::getCreateTime, reqVO.getBeginCreateTime(), reqVO.getEndCreateTime())
                .orderByDesc(McuTenantResourceDO::getId));
    }

    default List<McuTenantResourceDO> selectList(McuTenantResourceListReqVO  reqVO) {
        return selectList(new LambdaQueryWrapperX<McuTenantResourceDO>()
                .eqIfPresent(McuTenantResourceDO::getModel, reqVO.getModel())
                .likeIfPresent(McuTenantResourceDO::getName, reqVO.getName())
                .likeIfPresent(McuTenantResourceDO::getRemark, reqVO.getRemark())
                .eqIfPresent(McuTenantResourceDO::getCorrelationIp, reqVO.getCorrelationIp())
                .inIfPresent(McuTenantResourceDO::getId,reqVO.getIds())
                .eqIfPresent(McuTenantResourceDO::getTenantId,reqVO.getTenantId())
                .betweenIfPresent(McuTenantResourceDO::getCreateTime, reqVO.getBeginCreateTime(), reqVO.getEndCreateTime())
                .orderBy( true,Objects.nonNull(reqVO.getReverse())&&reqVO.getReverse(),McuTenantResourceDO::getId));
    }

    default List<McuTenantResourceDO> selectList(McuTenantResourceExportReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<McuTenantResourceDO>()
                .eqIfPresent(McuTenantResourceDO::getModel, reqVO.getModel())
                .likeIfPresent(McuTenantResourceDO::getName, reqVO.getName())
                .likeIfPresent(McuTenantResourceDO::getRemark, reqVO.getRemark())
                .eqIfPresent(McuTenantResourceDO::getCorrelationIp, reqVO.getCorrelationIp())
                .eqIfPresent(McuTenantResourceDO::getTenantId,reqVO.getTenantId())
                .betweenIfPresent(McuTenantResourceDO::getCreateTime, reqVO.getBeginCreateTime(), reqVO.getEndCreateTime())
                .orderByDesc(McuTenantResourceDO::getId));
    }

}
